// pages/authorization/authorization.js
import Ajax from '../../utils/request.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    authorizationStep: 2,
    hasUserInfo: false,
    showReturnBtn: false,
    showHomeBtn: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userInfoData: {}
  },
  goNextPageEvent(event) {
    let path = event.currentTarget.dataset['path'];
    wx.redirectTo({
      url: path
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getUserInfoEvent();
  },
  jianshezhongEvent() {
    wx.showToast({
      title: '建设中',
      icon: 'none',
      duration: 1000
    })
  },
  // 获取用户信息
  async getUserInfoEvent() {
    try {
      let res = await Ajax.get('/wxa/members/getUserInfo');
      console.log(res)
      if (res.code != 1) {
        wx.showToast({
          title: res.errorMsg,
          icon: 'none',
          duration: 2000
        })
        return false;
      }
      this.setData({
        userInfoData: res.result || {}
      })
      let _status = res.result.status
      app.userInfoReadyCallback = res => {
        app.globalData.isRealNameBool = _status
      }
      app.globalData.userData = res.result
    } catch (error) {
      console.log(error)
    }
  },
  /**
   * 
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})